<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="vue.global.js"></script>
</head>
<body>
<div id = 'app'>
    <!--    列表渲染需要增加key属性-》跟踪列表身份
            v-if v-for尽量不要使用-》利用计算属性来完成这类功能-->
    <div v-for="(item,index) in list" :key="item">{{item}},{{index}} , <input type="text"></div>

    <br>
    列表：<div v-for="(item,index) in list2" :key="item.id">{{item.id}},{{item.text}} , <input type="text"></div>

    <br>
    过滤后的列表：<div v-for="(item,index) in oddList" :key="item.id">{{item.id}},{{item.text}} , <input type="text"></div>

</div>
<script>
    const app = Vue.createApp({
        data() {
            return {
                list:['a','b','c','d'],
                list2:[{id:1,text:'a'},{id:2,text:'b'}]
            }
        },
        computed:{
            <!--利用计算属性来完成这类功能-->
            oddList(){
                return this.list2.filter((v) => v.id%2 === 1);
            }
        }

    });
    let vm = app.mount('#app');

    setTimeout(()=>{
        vm.list.unshift('e');
        vm.list2.unshift({id:3,text:'c'});
    },2000)

</script>
</body>
</html>